/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rhythm.commons.net.messaging;

import com.rhythm.base.Strings;
import com.rhythm.commons.validation.InvalidStateException;
import com.rhythm.commons.validation.ExceptionBuilder;
import com.rhythm.commons.validation.Validator;
import static com.rhythm.commons.validation.MessageType.*;

/**
 *
 * @author mlee
 */
    public class SimpleSMTPMessageValidator implements Validator<SimpleSMTPMessage> {

        public void checkState(SimpleSMTPMessage obj) throws InvalidStateException {
            ExceptionBuilder builder = new ExceptionBuilder();

            if (obj == null) {
                builder.assertNotNull(SEVERE, obj, "The SMTP message object referance is null.");
                builder.trySuppress();
                return;
            }

            builder.assertFalse(SEVERE, Strings.isEmptyOrNull(obj.getRecepient()), "Recepient is a required field and cannot be null or empty.");
            builder.assertFalse(SEVERE, Strings.isEmptyOrNull(obj.getSender()), "Sender is a required field and cannot be null or empty.");

            builder.trySuppress();
        }
    }
